import $ from 'jquery'
import 'bootstrap'
import 'bootstrap-select'

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-select/dist/css/bootstrap-select.css'
import 'styles/main.scss'
import 'styles/pages/loan.scss'

$(document).on('click', '.J_tabs a', e => {
  e.preventDefault()
  const $target = $(e.target)
  $target.parents('.J_tabs')
    .children('.active')
    .removeClass('active')
  $target.parent().addClass('active')
  const visible = $target.data('order')
  $('.J_order')[`${visible ? 'remove' : 'add'}Class`]('hide')
})

$(document).on('click', '.J_guarantee_btn', e => {
  e.preventDefault()
  const $tpl = $($('#guaranteeTpl').html())
  $tpl.children('.selectpicker').selectpicker()
  $('.J_guarantee').append($tpl)
})

$(document).on('click', '.J_account_edit', e => {
  e.preventDefault()
  const $target = $(e.target)
  if ($target.hasClass('btn--outline')) {
    $('.J_account')
      .removeClass('valid')
      .find('input[disabled]')
        .attr('disabled', false)
    $target
      .text('完成')
      .removeClass('btn--outline')
  } else {
    $('.J_account')
      .addClass('valid')
      .find('input')
        .attr('disabled', true)
    $target
      .addClass('btn--outline')
      .text('编辑')
  }
})
